<?php

	require_once(APPPATH . 'controllers/base_controllers/base_validation_controller.php');
	
	class Mahasamadhi_validation extends Base_validation_controller
	{
		
		public function __construct()
		{
			parent::__construct();
			
			$this->load->library('validation');
		}
		
		public function validate_registration( $eventID )
		{

			if (is_numeric($this->input->post('sponsoramount')))
				$sponsoramount = floatval($this->input->post('sponsoramount'));
			else
				$sponsoramount = 0;
				
			$numind = 0;
			$numadult = 0;
			$numchild = 0;
			$numchyk = 0;
			
			$regtype = $this->input->post('regtype');
			if ($regtype == "")
			{
				echo("<b>MUST SPECIFY A REGISTRATION TYPE</b>");
				die;				
			}
			
			$chykref = $this->input->post('chykref');
			
			switch ($regtype)
			{
				case 1:
					if( isset( $_POST['regfeeind'] ) )
						$regamount = $this->input->post('regfeeind');
					else
						$regamount = 0;
					break;
				case 2:
					if( isset( $_POST['regfeefam'] ) )
						$regamount = $this->input->post('regfeefam');
					else
						$regamount = 0;
					break;
				case 3:
					if( isset( $_POST['regfeechyk'] ) )
						$regamount = $this->input->post('regfeechyk');
					else
						$regamount = 0;
					break;
			}
						
			if ($regamount <= 0)
			{
				$numbiksha = 0;
				for($id = 0; $id < 5; $id++)
				{
					for($ie = 0; $ie < 3; $ie++)
					{
						$tag = strval(($id+1).($ie+1));
						if( isset( $_POST['boption'.$tag] ))
						{
							$numbiksha++;
						}
					}
				}
				
				$numarathi = 0;
				for($id = 0; $id < 5; $id++)
				{
					for($ie = 0; $ie < 3; $ie++)
					{
						$tag = strval(($id+1).($ie+1));
						if( isset( $_POST['aoption'.$tag] ))
						{
							$numarathi++;
						}
					}
				}				

				if (($numbiksha+$numarathi) <= 0)
				{
					echo("<b>MUST REGISTER AND/OR SPONSOR</b>");
					die;
				}
			}
						
			if ($regtype != "3")
			{
				if ($regtype == "1")
				{
					//Individual
					if ($this->input->post('isteacherind') == "")
					{
						echo("<b>MUST SPECIFY IF YOU ARE A CMB BALAVIHAR TEACHER</b>");
						die;						
					}
					
					$numind = intval($this->input->post('numind'));
					if ($numind <= 0)
					{
						echo("<b>MUST SPECIFY #INDIVIDUALS</b>");
						die;
					}

					if (($numind == 2) && isset( $_POST['regfeeind'] ))
					{
						if( intval($this->input->post('regfeeind')) == 4 )
						{
							echo("<b>ONLY ONE PERSON FOR SINGLE OCCUPANCY</b>");
							die;
						}
					}
/*
					if (($numind == 1) && isset( $_POST['regfeeind'] ))
					{
						if( intval($this->input->post('regfeeind')) == 1 )
						{
							echo("<b>NEED TO SPECIFY 2 PERSONS FOR DOUBLE OCCUPANCY</b>");
							die;
						}
					}
*/					
					$regcase = intval($this->input->post('regfeeind'));
				}
				else
				{
					//Family
					if ($this->input->post('isteacherfam') == "")
					{
						echo("<b>MUST SPECIFY IF YOU ARE A CMB BALAVIHAR TEACHER</b>");
						die;						
					}
					
					$numadult = intval($this->input->post('numadult'));
					$numchild = intval($this->input->post('numchild'));
					if ($numadult <= 0)
					{
						echo("<b>MUST SPECIFY #ADULTS</b>");
						die;
					}

					if (($numadult > 1) && isset( $_POST['regfeefam'] ))
					{
						if( intval($this->input->post('regfeefam')) == 4 )
						{
							echo("<b>ONLY ONE PERSON FOR SINGLE OCCUPANCY</b>");
							die;
						}
					}
					
					$regcase = intval($this->input->post('regfeefam'));
				}
			}
			else
			{
				if ($chykref == "")
				{
					echo("<b>MUST SPECIFY IF YOU WERE REFERRED TO THE CAMP</b>");
					die;				
				}
			
				if ($chykref == "yes")
				{
					$rules['chykRefFN'] = "trim|required|max_length[16]";
					$rules['chykRefLN'] = "trim|required|max_length[16]";
				}
				
				$numchyk = intval($this->input->post('numchyk'));
				if ($numchyk <= 0)
				{
					echo("<b>MUST SPECIFY #CHYK's</b>");
					die;
				}
					
				if (($numchyk > 2) && isset( $_POST['regfeechyk'] ))
				{
					if( intval($this->input->post('regfeechyk')) == 1 )
					{
						echo("<b>ONLY TWO PEOPLE FOR DOUBLE OCCUPANCY</b>");
						die;
					}
				}

				if (($numchyk > 3) && isset( $_POST['regfeechyk'] ))
				{
					if( intval($this->input->post('regfeechyk')) == 2 )
					{
						echo("<b>ONLY THREE PEOPLE FOR TRIPLE OCCUPANCY</b>");
						die;
					}
				}

				$regcase = intval($this->input->post('regfeechyk'));
			}
			
			$numtot = $numind + $numadult + $numchild + $numchyk;

			if ($regtype != "3")
			{
				switch ($regcase)
				{
					case 1:
						//Double occupancy
						if ($numtot > 2)
						{
							if ($numadult > 2)
							{	
								echo("<b>CANNOT EXCEED 2 ADULTS FOR DOUBLE OCCUPANCY</b>");
								die;
							}
							else
							{
								if ($numchild > 2)
								{
									echo("<b>CANNOT EXCEED 2 CHILDREN FOR DOUBLE OCCUPANCY</b>");
									die;									
								}
							}				
						}
	
						if (($numtot < 2) && ($regtype != 1))
						{
							echo("<b>NEED TO SPECIFY 2 PERSONS FOR DOUBLE OCCUPANCY</b>");
							die;				
						}
						break;
					
					case 2:
						//Triple occupancy
						if ($numtot > 3)
						{
							echo("<b>CANNOT EXCEED 3 PERSONS FOR TRIPLE OCCUPANCY</b>");
							die;				
						}	
						break;
					
					case 3:
						//Quad occupancy
						if ($regtype != 2)
						{
							//Family registration	
							if ($numtot > 4)
							{
								echo("<b>CANNOT EXCEED 4 PERSONS FOR QUAD OCCUPANCY</b>");
								die;				
							}
						}
						else
						{//Individual registration
								
							if (($numadult == 3) && ($numchild > 1))
							{
								echo("<b>CAN ONLY SUPPORT ONE CHILD WITH 3 ADULTS FOR QUAD OCCUPANCY</b>");
								die;				
							}
						}	
						break;
					
					case 4:
						//Single occupancy
						if ($numtot > 1)
						{
							echo("<b>CANNOT EXCEED 2 ATTENDEES FOR SINGLE OCCUPANCY</b>");
							die;				
						}
						break;
				}
			}
			
			for($i=1; $i<=$numind; $i++)
			{
				$rules['indFN'.$i] = "trim|required|max_length[16]";
				$rules['indLN'.$i] = "trim|required|max_length[16]";
				$rules['indG'.$i] = "trim|required|max_length[8]";
				
				/* $ia = $this->input->post('ia'.$i);
				if ($ia == "")
				{
					echo("<b>MUST SPECIFY INDIVIDUAL#".$i." ALLERGY or 'None'</b>");
					die;				
				} */
			}

			for($i=1; $i<=$numadult; $i++)
			{
				$rules['adultFN'.$i] = "trim|required|max_length[16]";
				$rules['adultLN'.$i] = "trim|required|max_length[16]";
				$rules['adultG'.$i] = "trim|required|max_length[8]";
				
				/* $aa = $this->input->post('aa'.$i);
				if ($aa == "")
				{
					echo("<b>MUST SPECIFY ADULT#".$i." ALLERGY or 'None'</b>");
					die;				
				} */
			}

			for($i=1; $i<=$numchild; $i++)
			{
				$rules['childFN'.$i] = "trim|required|max_length[16]";
				$rules['childLN'.$i] = "trim|required|max_length[16]";
				$rules['childG'.$i] = "trim|required|max_length[8]";

				$childAge = intval($this->input->post('childAge'.$i));
				if ($childAge < 4)
				{
					echo("<b>CHILD#".$i." AGE MUST BE GREATER THAN 3yrs</b>");
					die;				
				}
				
				if( !isset( $_POST['ischyk'.$i] ) )
				{
					if ($childAge > 17)
					{
						echo("<b>CHILD#".$i." AGE MUST BE LESS THAN 18yrs</b>");
						die;				
					}
				}
				else
				{
					if ($childAge < 18)
					{
						echo("<b>CHILD#".$i." AGE MUST BE GREATER THAN 17yrs FOR CHYK MEMBER</b>");
						die;				
					}					
				}
				
				/* $ca = $this->input->post('ca'.$i);
				if ($ca == "")
				{
					echo("<b>MUST SPECIFY CHILD#".$i." ALLERGY or 'None'</b>");
					die;				
				} */
			}
			
			for($i=1; $i<=$numchyk; $i++)
			{
				$rules['chykFN'.$i] = "trim|required|max_length[16]";
				$rules['chykLN'.$i] = "trim|required|max_length[16]";
				$rules['chykG'.$i] = "trim|required|max_length[8]";
				
				/* $cha = $this->input->post('cha'.$i);
				if ($cha == "")
				{
					echo("<b>MUST SPECIFY CHYK#".$i." ALLERGY or 'None'</b>");
					die;				
				} */
			}

			switch ($eventID)
			{
				case 1:
					//$rules['lastname'] = "trim|required|max_length[16]";
					//$rules['firstname'] = "trim|required|max_length[16]";
					if ( isset( $_POST['needaccommodation'] ) )
						$rules['needaccommodation'] = "trim|required";
					$rules['email'] = "trim|required|valid_email|matches[emailConfirm]|max_length[127]";
					$rules['phoneNumber'] = "trim|required|callback_valid_phone_check|max_length[16]";
					$rules['address'] = "trim|required|alpha_address|min_length[1]|max_length[127]";
					$rules['city'] = "trim|required|alpha_dash|min_length[1]|max_length[63]";
					
					$rules['stateusa'] = "trim|max_length[31]";
					$rules['stateglobal'] = "trim|max_length[31]";
					$stateusa = $this->input->post('stateusa');
					$stateglobal = $this->input->post('stateglobal');

					$rules['country'] = "trim|required|max_length[63]";
					if ($this->input->post('country') == "NON")
					{
						echo("<b>MUST SPECIFY COUNTRY</b>");
						die;				
					}

					if (($stateusa == "") && ($stateglobal == ""))
					{
						echo("<b>MUST SPECIFY A State/Province</b>");
						die;
					}

					$rules['zip'] = "trim|required|alpha_dash|min_length[2]|max_length[16]";
		
					
					$this->validation->set_rules($rules);	
					$validationPassed = $this->validation->run();
					
					if($validationPassed)
					{
						echo( 'VALIDATION_SUCCESS' );
					}
					else
					{
						echo( $this->clean_validation_errors_validate_registration( $this->validation->error_string, $eventID ) );
					}
					break;
			}
			
			die;
		}

		public function validate_event_release_check()
		{
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
			
			//Get check info
			$curyear = $this->Walk_proxy->getCurrentYear();
			$RegIdArray = $this->Mahasamadhi_proxy->getEventUnpaidCheckRegId( $curyear );

			if (count($RegIdArray) > 0)
			{
				$flg = false;
				//CheckInfo
				for( $i = 0; $i < count($RegIdArray); $i++ )
				{
					$checknum = $this->input->post('msid'.$RegIdArray[$i]);
					if ($checknum != "")
					{
						$rules['msid'.$RegIdArray[$i]] = "trim|required|alpha_dash|min_length[1]|max_length[16]";
						$rules['msidca'.$RegIdArray[$i]] = "trim|required|numeric|min_length[1]|max_length[16]";
						$flg = true;
					}
				}
			
				if ($flg)
				{
					$this->validation->set_rules($rules);	
					$validationPassed = $this->validation->run();
				}
				else
					$validationPassed = true;
			}
			else
			{
				$validationPassed = true;
			}
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_validate_event_release_check( $this->validation->error_string, $RegIdArray ) );
			}
			
			die;
		}
		
		public function validate_admin_edit_reg( $eventID )
		{

			if (is_numeric($this->input->post('sponsoramount')))
				$sponsoramount = floatval($this->input->post('sponsoramount'));
			else
				$sponsoramount = 0;
				
			$numind = 0;
			$numadult = 0;
			$numchild = 0;
			$numchyk = 0;
			
			$regtype = $this->input->post('regtype');
			if ($regtype == "")
			{
				echo("<b>MUST SPECIFY A REGISTRATION TYPE</b>");
				die;				
			}
			
			$chykref = $this->input->post('chykref');
			
			switch ($regtype)
			{
				case 1:
					if( isset( $_POST['regcaseind'] ) )
						$regcase = $this->input->post('regcaseind');
					else
						$regcase = 0;
			
					break;
				case 2:
					if( isset( $_POST['regcasefam'] ) )
						$regcase = $this->input->post('regcasefam');
					else
						$regcase = 0;
			
					break;
				case 3:
					if( isset( $_POST['regcasechyk'] ) )
						$regcase = $this->input->post('regcasechyk');
					else
						$regcase = 0;
			
					break;
			}
			
			if ($regcase <= 0)
			{
				$numbiksha = 0;
				for($id = 0; $id < 5; $id++)
				{
					for($ie = 0; $ie < 3; $ie++)
					{
						$tag = strval(($id+1).($ie+1));
						if( isset( $_POST['boption'.$tag] ))
						{
							$numbiksha++;
						}
					}
				}
				
				$numarathi = 0;
				for($id = 0; $id < 5; $id++)
				{
					for($ie = 0; $ie < 3; $ie++)
					{
						$tag = strval(($id+1).($ie+1));
						if( isset( $_POST['aoption'.$tag] ))
						{
							$numarathi++;
						}
					}
				}				

				if (($numbiksha+$numarathi) <= 0)
				{
					echo("<b>MUST REGISTER AND/OR SPONSOR</b>");
					die;
				}
			}
						
			if ($regtype != "3")
			{
				if ($regtype == "1")
				{
					//Individual
					if ($this->input->post('isteacherind') == "")
					{
						echo("<b>MUST SPECIFY IF YOU ARE A CMB BALAVIHAR TEACHER</b>");
						die;						
					}
					
					$numind = intval($this->input->post('numind'));
					if ($numind <= 0)
					{
						echo("<b>MUST SPECIFY #INDIVIDUALS</b>");
						die;
					}

					if (($numind == 2) && isset( $_POST['regcaseind'] ))
					{
						if( intval($this->input->post('regcaseind')) == 4 )
						{
							echo("<b>ONLY ONE PERSON FOR SINGLE OCCUPANCY</b>");
							die;
						}
					}
/*
					if (($numind == 1) && isset( $_POST['regcaseind'] ))
					{
						if( intval($this->input->post('regcaseind')) == 1 )
						{
							echo("<b>NEED TO SPECIFY 2 PERSONS FOR DOUBLE OCCUPANCY</b>");
							die;
						}
					}
*/
				}
				else
				{
					//Family
					if ($this->input->post('isteacherfam') == "")
					{
						echo("<b>MUST SPECIFY IF YOU ARE A CMB BALAVIHAR TEACHER</b>");
						die;						
					}
					
					$numadult = intval($this->input->post('numadult'));
					$numchild = intval($this->input->post('numchild'));
					if ($numadult <= 0)
					{
						echo("<b>MUST SPECIFY #ADULTS</b>");
						die;
					}

					if (($numadult > 1) && isset( $_POST['regcasefam'] ))
					{
						if( intval($this->input->post('regcasefam')) == 4 )
						{
							echo("<b>ONLY ONE PERSON FOR SINGLE OCCUPANCY</b>");
							die;
						}
					}
				}
			}
			else
			{
				if ($chykref == "")
				{
					echo("<b>MUST SPECIFY IF YOU WERE REFERRED TO THE CAMP</b>");
					die;				
				}
			
				if ($chykref == "yes")
				{
					$rules['chykRefFN'] = "trim|required|max_length[16]";
					$rules['chykRefLN'] = "trim|required|max_length[16]";
				}
				
				$numchyk = intval($this->input->post('numchyk'));
				if ($numchyk <= 0)
				{
					echo("<b>MUST SPECIFY #CHYK's</b>");
					die;
				}

				if (($numchyk > 2) && isset( $_POST['regfeechyk'] ))
				{
					if( intval($this->input->post('regfeechyk')) == 1 )
					{
						echo("<b>ONLY TWO PEOPLE FOR DOUBLE OCCUPANCY</b>");
						die;
					}
				}

				if (($numchyk > 3) && isset( $_POST['regfeechyk'] ))
				{
					if( intval($this->input->post('regfeechyk')) == 2 )
					{
						echo("<b>ONLY THREE PEOPLE FOR TRIPLE OCCUPANCY</b>");
						die;
					}
				}
			}
			
			if ($regtype != "3")
			{
				if( $regcase > 0)
				{
					$numtot = $numind + $numadult + $numchild + $numchyk;
					switch ($regcase)
					{
						case 1:
							//Double occupancy
							if ($numtot > 2)
							{
								if ($numadult > 2)
								{	
									echo("<b>CANNOT EXCEED 2 ADULTS FOR DOUBLE OCCUPANCY</b>");
									die;
								}
								else
								{
									if ($numchild > 2)
									{
										echo("<b>CANNOT EXCEED 2 CHILDREN FOR DOUBLE OCCUPANCY</b>");
										die;									
									}
								}				
							}
		
							if (($numtot < 2) && ($regtype != 1))
							{
								echo("<b>NEED TO SPECIFY 2 PERSONS FOR DOUBLE OCCUPANCY</b>");
								die;				
							}
							break;
						
						case 2:
							//Triple occupancy
							if ($numtot > 3)
							{
								echo("<b>CANNOT EXCEED 3 PERSONS FOR TRIPLE OCCUPANCY</b>");
								die;				
							}
							break;
						
						case 3:
							//Quad occupancy
							if ($regtype != 2)
							{
								if ($numtot > 4)
								{
									echo("<b>CANNOT EXCEED 4 PERSONS FOR QUAD OCCUPANCY</b>");
									die;				
								}
							}
							else
							{
								if (($numadult == 3) && ($numchild > 1))
								{
									echo("<b>CAN ONLY SUPPORT ONE CHILD WITH 3 ADULTS FOR QUAD OCCUPANCY</b>");
									die;				
								}
							}
							break;
						
						case 4:
							//Single occupancy
							if ($numtot > 1)
							{
								echo("<b>CANNOT EXCEED 2 PERSONS FOR SINGLE OCCUPANCY</b>");
								die;				
							}
							break;
					}
				}
			}
			
			for($i=1; $i<=$numind; $i++)
			{
				$rules['indFN'.$i] = "trim|required|max_length[16]";
				$rules['indLN'.$i] = "trim|required|max_length[16]";
				$rules['indG'.$i] = "trim|required|max_length[8]";
				
				/* $ia = $this->input->post('ia'.$i);
				if ($ia == "")
				{
					echo("<b>MUST SPECIFY INDIVIDUAL#".$i." ALLERGY or 'None'</b>");
					die;				
				} */
			}

			for($i=1; $i<=$numadult; $i++)
			{
				$rules['adultFN'.$i] = "trim|required|max_length[16]";
				$rules['adultLN'.$i] = "trim|required|max_length[16]";
				$rules['adultG'.$i] = "trim|required|max_length[8]";
				
				/* $aa = $this->input->post('aa'.$i);
				if ($aa == "")
				{
					echo("<b>MUST SPECIFY ADULT#".$i." ALLERGY or 'None'</b>");
					die;				
				} */
			}

			for($i=1; $i<=$numchild; $i++)
			{
				$rules['childFN'.$i] = "trim|required|max_length[16]";
				$rules['childLN'.$i] = "trim|required|max_length[16]";
				$rules['childG'.$i] = "trim|required|max_length[8]";

				$childAge = intval($this->input->post('childAge'.$i));
				if ($childAge < 4)
				{
					echo("<b>CHILD#".$i." AGE MUST BE GREATER THAN 3yrs</b>");
					die;				
				}
				
				if( !isset( $_POST['ischyk'.$i] ) )
				{
					if ($childAge > 17)
					{
						echo("<b>CHILD#".$i." AGE MUST BE LESS THAN 18yrs</b>");
						die;				
					}
				}
				else
				{
					if ($childAge < 18)
					{
						echo("<b>CHILD#".$i." AGE MUST BE GREATER THAN 17yrs FOR CHYK MEMBER</b>");
						die;				
					}					
				}
				
				/* $ca = $this->input->post('ca'.$i);
				if ($ca == "")
				{
					echo("<b>MUST SPECIFY CHILD#".$i." ALLERGY or 'None'</b>");
					die;				
				} */
			}
			
			for($i=1; $i<=$numchyk; $i++)
			{
				$rules['chykFN'.$i] = "trim|required|max_length[16]";
				$rules['chykLN'.$i] = "trim|required|max_length[16]";
				$rules['chykG'.$i] = "trim|required|max_length[8]";
				
				/* $cha = $this->input->post('cha'.$i);
				if ($cha == "")
				{
					echo("<b>MUST SPECIFY CHYK#".$i." ALLERGY or 'None'</b>");
					die;				
				} */
			}

			switch ($eventID)
			{
				case 1:
					//$rules['lastname'] = "trim|required|max_length[16]";
					//$rules['firstname'] = "trim|required|max_length[16]";
					if ( isset( $_POST['needaccommodation'] ) )
						$rules['needaccommodation'] = "trim|required";
					
					$rules['email'] = "trim|required|valid_email|matches[emailConfirm]|max_length[127]";
					$rules['phoneNumber'] = "trim|required|callback_valid_phone_check|max_length[16]";
					$rules['address'] = "trim|required|alpha_address|min_length[1]|max_length[127]";
					$rules['city'] = "trim|required|alpha_dash|min_length[1]|max_length[63]";
					
					$rules['stateusa'] = "trim|max_length[31]";
					$rules['stateglobal'] = "trim|max_length[31]";
					$stateusa = $this->input->post('stateusa');
					$stateglobal = $this->input->post('stateglobal');

					$rules['country'] = "trim|required|max_length[63]";
					if ($this->input->post('country') == "NON")
					{
						echo("<b>MUST SPECIFY COUNTRY</b>");
						die;				
					}

					if (($stateusa == "") && ($stateglobal == ""))
					{
						echo("<b>MUST SPECIFY A State/Province</b>");
						die;
					}

					$rules['zip'] = "trim|required|alpha_dash|min_length[2]|max_length[16]";
					//$rules['zip'] = "trim|callback_valid_zip_code_check|max_length[10]";
		
					
					$this->validation->set_rules($rules);	
					$validationPassed = $this->validation->run();
					
					if($validationPassed)
					{
						echo( 'VALIDATION_SUCCESS' );
					}
					else
					{
						echo( $this->clean_validation_errors_validate_registration( $this->validation->error_string, $eventID ) );
					}
					break;
			}
			
			die;
		}
/*
		public function validate_admin_edit_reg()
		{
			$numadult = intval($this->input->post('numadult'));
			if ($numadult <= 0)
			{
				echo("<b>MUST SPECIFY #ADULTS</b>");
				die;
			}
			
			$stateusa = $this->input->post('stateusa');
			$stateglobal = $this->input->post('stateglobal');
			if (($stateusa == "") && ($stateglobal == ""))
			{
				echo("<b>MUST SPECIFY A State/Province</b>");
				die;
			}

			if (is_numeric($this->input->post('sponsoramount')))
				$sponsoramount = floatval($this->input->post('sponsoramount'));
			else
				$sponsoramount = 0;
				
			$rules['lastname'] = "trim|required|max_length[16]";
			$rules['firstname'] = "trim|required|max_length[16]";
			$rules['email'] = "trim|required|valid_email|matches[emailConfirm]|max_length[127]";
			$rules['phoneNumber'] = "trim|required|callback_valid_phone_check|max_length[12]";
			$rules['address'] = "trim|required|alpha_address|min_length[1]|max_length[127]";
			$rules['city'] = "trim|required|alpha_dash|min_length[1]|max_length[63]";
			$rules['stateusa'] = "trim|max_length[31]";
			$rules['stateglobal'] = "trim|max_length[31]";
			$rules['country'] = "trim|required|max_length[63]";
			$rules['zip'] = "trim|required|callback_valid_zip_code_check|max_length[10]";
			
			$this->validation->set_rules($rules);	
			$validationPassed = $this->validation->run();
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_validate_admin_edit_reg( $this->validation->error_string ) );
			}
			
			die;
		}
*/
		private function clean_validation_errors_validate_registration( $valErrors, $eventID )
		{
			switch ($eventID)
			{
				case 1:
					$numind = 0;
					$numadult = 0;
					$numchild = 0;
					$numchyk = 0;
	
					$chykref = $this->input->post('chykref');
					if ($chykref == "yes")
					{
						$valErrors = str_replace("chykRefFN", "Referrer First Name", $valErrors);
						$valErrors = str_replace("chykRefLN", "Referrer Last Name", $valErrors);						
					}
					
					//$valErrors = str_replace("firstname", "First name", $valErrors);
					//$valErrors = str_replace("lastname", "Last name", $valErrors);
					if ( isset( $_POST['needaccommodation'] ) )
						$valErrors = str_replace("needaccommodation", "Need Accommodation", $valErrors);
					$valErrors = str_replace("email", "Email", $valErrors);
					$valErrors = str_replace("emailConfirm", "Confirm Email", $valErrors);
					$valErrors = str_replace("phoneNumber", "Phone Number", $valErrors);
					$valErrors = str_replace("address", "Address", $valErrors);
					$valErrors = str_replace("city", "City", $valErrors);
					$valErrors = str_replace("state", "State/Province", $valErrors);
					$valErrors = str_replace("country", "Country", $valErrors);
					$valErrors = str_replace("zip", "Postal Code", $valErrors);

					$regtype = $this->input->post('regtype');
					if ($regtype != "3")
					{
						if ($regtype == "1")
						{
							$numind = intval($this->input->post('numind'));
						}
						else
						{
							$numadult = intval($this->input->post('numadult'));
						}
					}
					else
					{
						$numchyk = intval($this->input->post('numchyk'));
					}

					for($i=1; $i<=$numind; $i++)
					{
						if ($i == 1)
						{
							$valErrors = str_replace("indFN".$i, "Primary Individual First Name", $valErrors);
							$valErrors = str_replace("indLN".$i, "Primary Individual Last Name", $valErrors);
							$valErrors = str_replace("indG".$i, "Primary Individual Gender", $valErrors);
						}
						else
						{
							$valErrors = str_replace("indFN".$i, "Individual#".$i." First Name", $valErrors);
							$valErrors = str_replace("indLN".$i, "Individual#".$i." Last Name", $valErrors);
							$valErrors = str_replace("indG".$i, "Individual".$i." Gender", $valErrors);
						}
					}

					for($i=1; $i<=$numadult; $i++)
					{
						if ($i == 1)
						{
							$valErrors = str_replace("adultFN".$i, "Primary Adult First Name", $valErrors);
							$valErrors = str_replace("adultLN".$i, "Primary Adult Last Name", $valErrors);
							$valErrors = str_replace("adultG".$i, "Primary Adult Gender", $valErrors);
						}
						else
						{
							$valErrors = str_replace("adultFN".$i, "Adult#".$i." First Name", $valErrors);
							$valErrors = str_replace("adultLN".$i, "Adult#".$i." Last Name", $valErrors);
							$valErrors = str_replace("adultG".$i, "Adult".$i." Gender", $valErrors);
						}
					}

					for($i=1; $i<=$numchild; $i++)
					{
						$valErrors = str_replace("childFN".$i, "Child#".$i." First Name", $valErrors);
						$valErrors = str_replace("childLN".$i, "Child#".$i." Last Name", $valErrors);
						$valErrors = str_replace("childG".$i, "Child#".$i." Gender", $valErrors);
					}

					for($i=1; $i<=$numchyk; $i++)
					{
						if ($i == 1)
						{
							$valErrors = str_replace("chykFN".$i, "Primary CHYK First Name", $valErrors);
							$valErrors = str_replace("chykLN".$i, "Primary CHYK Last Name", $valErrors);
							$valErrors = str_replace("chykG".$i, "Primary CHYK Gender", $valErrors);
						}
						else
						{
							$valErrors = str_replace("chykFN".$i, "CHYK#".$i." First Name", $valErrors);
							$valErrors = str_replace("chykLN".$i, "CHYK#".$i." Last Name", $valErrors);
							$valErrors = str_replace("chykG".$i, "CHYK#".$i." Gender", $valErrors);
						}
					}

					break;
			}
									
			return $valErrors;
		}		

		private function clean_validation_errors_validate_event_release_check( $valErrors, $RegIdArray )
		{

			if (count($RegIdArray) > 0)
			{
				//CheckInfo
				for( $i = 0; $i < count($RegIdArray); $i++ )
				{
					$checknum = $this->input->post('bqid'.$RegIdArray[$i]);
					if ($checknum != "")
					{
						$valErrors = str_replace("'bqid'.$RegIdArray[$i]", "Check #", $valErrors);
					}
				}					
			}
			
			return $valErrors;
		}

		private function clean_validation_errors_validate_admin_edit_reg( $valErrors )
		{
			if ( isset( $_POST['needaccommodation'] ) )	
				$valErrors = str_replace("needaccommodation", "Need Accommodation", $valErrors);
			$valErrors = str_replace("firstname", "First name", $valErrors);
			$valErrors = str_replace("lastname", "Last name", $valErrors);
			$valErrors = str_replace("email", "Email", $valErrors);
			$valErrors = str_replace("emailConfirm", "Confirm Email", $valErrors);
			$valErrors = str_replace("phone", "Phone Number", $valErrors);
			$valErrors = str_replace("address", "Address", $valErrors);
			$valErrors = str_replace("city", "City", $valErrors);
			$valErrors = str_replace("state", "State", $valErrors);
			$valErrors = str_replace("country", "Country", $valErrors);
			$valErrors = str_replace("zip", "Zip Code", $valErrors);
			$valErrors = str_replace("numadultreg", "Number adults", $valErrors);
			$valErrors = str_replace("numchildreg", "Number children", $valErrors);
			$valErrors = str_replace("donationamount", "Donation", $valErrors);
			$valErrors = str_replace("paymenttype", "Payment Type", $valErrors);
			//$valErrors = str_replace("checknum", "Check #", $valErrors);
			//$valErrors = str_replace("paytxn", "CC TXN ID", $valErrors);
			//$valErrors = str_replace("paymentstatus", "Payment Status", $valErrors);
			//$valErrors = str_replace("comments", "Comments", $valErrors);
									
			return $valErrors;
		}		
	}

?>